<template>
  <div class="goods-item" @click="itemClick">
    <img :src="goodsItem.goods_small_logo" alt="" @error="defaultImg(goodsItem)">
    <div class="goods-info">
      <p>{{goodsItem.goods_name}}</p>
      <span class="goods-price">￥{{goodsItem.goods_price}}</span>
      <span class="goods-number">{{goodsItem.goods_number}}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'GoodsItem',
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    itemClick() {
      this.$router.push('/detail/'+this.goodsItem.goods_id)
    },
    defaultImg(goodsItem) {
      goodsItem.goods_small_logo = require('assets/img/default.png')
    }
  }
}
</script>

<style scoped>
  .goods-item {
    padding-bottom: 40px;
    position: relative;
    width: 48%;
  }
  .goods-item img {
    width: 100%;
    border-radius: 5px;
  }

.goods-info {
  font-size: 14px;
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  overflow: hidden ;
  text-align: center;
}

.goods-info p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}
.goods-info .goods-number {
  position: relative;
}
.goods-info .goods-number::before {
  content: '';
  position: absolute;
  left: -15px;
  top: 2px;
  width: 14px;
  height: 14px;
  background: url("~assets/img/start.png") 0 0/14px 14px;
}

.goods-price {
  color: var(--color-high-text);
  margin-right: 20px;
}
</style>
